package Exception2;

public class BinaryToDecimal {
    static int binaryToDecimal(String Binary)  throws BinaryFormatException{
        int decimal_value = 0;
        for(int i = 0; i < Binary.length(); i++){
            if(Binary.charAt(i) == '0' || Binary.charAt(i) == '1'){
                decimal_value += Binary.charAt(i) - '0';
                decimal_value *= 2;
            }
            else{
                throw new BinaryFormatException("Binary string contain symbols other than 0 and 1.");
            }
        }
        return decimal_value/2;
    }
}